<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .layui-form-item .layui-input-inline {
            float: left;
            width: 127px;
            margin-right: 10px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" id="formInfo">
            <!--<fieldset class="table-search-fieldset">-->
            <!--<legend>搜索信息</legend>-->
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索信息</label>
                        <div class="layui-input-inline">
                            <input type="text"  name="searchInfo" placeholder="姓名/手机号/ID" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                     <div class="layui-inline" style="display: none">
                         <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                     </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">注册时间</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="register_min" id="register_min" placeholder="起始日期" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="register_max" id="register_max" placeholder="结束日期" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline" id="area-picker">
                        <div class="layui-form-label">地区筛选</div>
                        <div class="layui-input-inline">
                            <select name="province" class="province-selector" lay-filter="province-1">
                                <option value="">请选择省</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="city" class="city-selector" lay-filter="city-1">
                                <option value="">请选择市</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="area" class="county-selector" lay-filter="county-1">
                                <option value="">请选择区</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <select name="type" lay-filter="selectInfo">
                                <option value=""></option>
                                <option value="2">合伙人</option>
                                <option value="1">账号正常</option>
                                <option value="3">账号封停</option>
                                <option value="4">玩家退出</option>
                                <option value="5">未赠送</option>
                                <option value="6">已赠送</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">虚拟用户</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <select name="fictitious" lay-filter="selectInfo">
                                    <option value="">全部</option>
                                    <option value="0">正常用户</option>
                                    <option value="1">虚拟用户</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">等级</label>
                        <div class="layui-input-inline">
                            <input type="hidden" name="level" id="levelHidden">
                            <input type="text" placeholder="请选择" autocomplete="off" class="layui-input" id="level">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">团队</label>
                        <div class="layui-input-inline" style="width: 224px">
                            <input type="hidden" name="team_id" id="teamHidden">
                            <input type="text" placeholder="请选择" autocomplete="off" class="layui-input" id="team">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">收益金额</label>
                        <div class="layui-input-inline" style="width: 120px">
                            <select name="income" lay-filter="selectInfo">
                                <option value=""></option>
                                <option value="300">300以下</option>
                                <option value="800">800以下</option>
                                <option value="1500">1500以下</option>
                                <option value="3000">3000以下</option>
                                <option value="5000">5000以下</option>
                                <option value="8000">8000以下</option>
                                <option value="15000">15000以下</option>
                                <option value="25000">25000以下</option>
                                <option value="40000">40000以下</option>
                                <option value="60000">60000以下</option>
                                <option value="60000.0">60000以上</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">违规玩家</label>
                        <div class="layui-input-inline" style="width: 145px">
                            <select name="infraction" lay-filter="selectInfo">
                                <option value=""></option>
                                <option value="0,3">违规3次以下</option>
                                <option value="3,6">违规3-6次</option>
                                <option value="6,10">违规6-10次</option>
                                <option value="10">违规10次以上</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-inline" style="width: 100px">
                            <select name="sex" lay-filter="selectInfo">
                                <option value=""></option>
                                <option value="1">男</option>
                                <option value="2">女</option>
                            </select>
                        </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">年龄</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <select name="age" lay-filter="selectInfo">
                                <option value=""></option>
                                <option value="0,20">20岁以下</option>
                                <option value="20,30">20-30</option>
                                <option value="30,40">30-40</option>
                                <option value="40,50">40-50</option>
                                <option value="50,60">50-60</option>
                                <option value="60">60以上</option>
                            </select>
                        </div>
                    </div>
                    </div>
                </div>
            </div>
            <!--</fieldset>-->
            <input type="hidden" name="buttonHidden" id="buttonHidden">
        </form>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
                <button class="layui-btn layui-bg-black" style="margin-left: 15%" lay-event="countNum"> 当前总数 : <span id="countNum"></span></button>
                <button class="layui-btn layui-bg-black" lay-event="activated"> 已激活 : <span id="activated"></span></button>
                <button class="layui-btn layui-bg-black" lay-event="fictitious"> 虚拟用户 : <span id="fictitious"></span></button>
                <button class="layui-btn layui-bg-black" lay-event="notActive"> 未激活 : <span id="notActive"></span></button>
                <button class="layui-btn layui-bg-black" lay-event="notGiving"> 未赠送 : <span id="notGiving"></span></button>
                <button class="layui-btn layui-bg-black"> 收益总额 : <span id="incomeTotal"></span></button>
                <button class="layui-btn layui-bg-black"> 金币数量 : <span id="goldTotal"></span></button>
                <button class="layui-btn layui-bg-black"> 积分总量 : <span id="integralTotal"></span></button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        </script>

    </div>
</div>
{include file="public/footer" /}
<!--活跃状态-->
<script type="text/html" id="activeTpl">
    {{#  if(d.activeState == 0){ }}
    <span style="color: #F581B1;"> 活跃</span>
    {{#  } else { }}
    <span>不活跃</span>
    {{#  } }}
</script>
<!--性别-->
<script type="text/html" id="sexTpl">
    {{#  if(d.sex === 2){ }}
    <span style="color: #F581B1;"> 女</span>
    {{#  } else { }}
    <span>男</span>
    {{#  } }}
</script>
<script type="text/html" id="typeTpl">
    {{#  if(d.type === 1){ }}
    <span style="color: #28f51d;">账号正常</span>
    {{# }else if(d.type === 2){ }}
    <span style="color: #f59b28;">合伙人</span>
    {{# }else if(d.type === 3){ }}
    <span style="color: #f42540;">账号封停</span>
    {{#  } else { }}
    <span style="color: rgba(0,0,0,0.11);">玩家退出</span>
    {{#  } }}
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status === 1){ }}
    <span>未注册</span>
    {{# }else if(d.status === 2){ }}
    <span>已注册</span>
    {{# }else if(d.status === 3){ }}
    <span>未激活</span>
    {{# }else if(d.status === 4){ }}
    <span>等待审核</span>
    {{#  } else { }}
    <span>已激活</span>
    {{#  } }}
</script>
<script type="text/html" id="givingTpl">
    {{#  if(d.giving_status === 1){ }}
    <span>未赠送</span>
    {{# }else if(d.giving_status === 2){ }}
    <span>已赠送</span>
    {{#  } }}
</script>

<script>
    var checkmark="{$checkmark}";
    var checklevel="{$checklevel}";
    var canUseLevel="{$canUseLevel}";
    var lanunchdetail="{$lanunchdetail}";
    var team_id="{$team_id}";
    layui.use(['form', 'table', 'laydate', 'layarea', 'tableSelect'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layarea = layui.layarea,
            tableSelect = layui.tableSelect;
        /*注册时间-最小*/
        laydate.render({
            elem: '#register_min',
            done(value,date){
                $('#register_min').val(value);
                $('#buttonHidden').val('');
                submitInfo();
            }
        });
        /*注册时间-最大*/
        laydate.render({
            elem: '#register_max',
            done(value,date){
                $('#register_max').val(value);
                $('#buttonHidden').val('');
                submitInfo();
            }
        });
        /*等级筛选*/
        tableSelect.render({
            elem: '#level',
            searchKey: 'title',
            checkedKey: 'level',
            searchPlaceholder: '名称搜索',
            table: {
                url: '/admin/Member/memberLevelInfo?action=ajax',
                method: 'post',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data, //解析数据列表
                    };
                },
                cols: [[
                    {type: 'checkbox'},
                    {field: 'level', title: '等级', sort: true},
                    {field: 'title', title: '名称', sort: true},
                ]],
                page: true,
                limits: [15, 20, 25, 30, 50, 100],
                limit: 15
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var levelHidden = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.title)
                    levelHidden.push(item.level)
                })
                elem.val(NEWJSON.join(","))
                $('#levelHidden').val(levelHidden.join(","));
                submitInfo();
            }
        });
        /*团队筛选*/
        tableSelect.render({
            elem: '#team',
            searchKey: 'title',
            checkedKey: 'id',
            searchPlaceholder: '名称搜索',
            table: {
                url: '/admin/Member/teamInfo?action=ajax',
                method: 'post',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data, //解析数据列表
                    };
                },
                cols: [[
                    {type: 'checkbox'},
                    {field: 'title', title: '团队名称', sort: true},
                    {field: 'team_num', title: '团队人数', sort: true},
                    {field: 'income', title: '团队总收益', sort: true},
                ]],
                page: true,
                limits: [10, 15, 20, 25, 30, 50, 100],
                limit: 10
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var teamHidden = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.title)
                    teamHidden.push(item.id)
                })
                elem.val(NEWJSON.join(","))
                $('#teamHidden').val(teamHidden.join(","));
                $('#buttonHidden').val('');
                submitInfo();
            }
        });
        /*城市级联*/
        layarea.render({
            elem: '#area-picker',
            change: function (res) {
                //选择结果
                $('#buttonHidden').val('');
                submitInfo();
            }
        });
        /*玩家列表*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/Member/index?action=ajax&lanunchdetail='+lanunchdetail+'&checkmark='+checkmark+'&canUseLevel='+canUseLevel+"&checklevel="+checklevel+"&team_id="+team_id,
            method: 'post',
            where: {mark: "{$mark}", address: "{$address}", level: "{$level}", age: "{$age}",'team':"{$team}"},
            parseData: function (res) { //res 即为原始返回的数据
                $('#countNum').html(res.data.info.total);
                $('#activated').html(res.data.statistics.activated);
                $('#fictitious').html(res.data.statistics.fictitious);
                $('#notActive').html(res.data.statistics.notActive);
                $('#notGiving').html(res.data.statistics.notGiving);
                $('#incomeTotal').html(parseFloat(res.data.statistics.total.incomeTotal).toFixed(2));
                $('#goldTotal').html(parseFloat(res.data.statistics.total.goldTotal).toFixed(2));
                $('#integralTotal').html(parseFloat(res.data.statistics.total.integralTotal).toFixed(2));
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.info.total, //解析数据长度
                    "data": res.data.info.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'name', title: '玩家名称', sort: true,},
                {field: 'code', title: '玩家ID', sort: true, minWidth: 120},
                {field: 'phone', title: '手机号', sort: true, minWidth: 120},
                {field: 'register_time', title: '注册日期', sort: true, minWidth: 160},
                {field: 'levelTitle', title: '玩家等级', sort: true,},
                {field: 'teamTitle', title: '所属团队', sort: true},
                {field: 'sex', title: '性别', sort: true, templet: '#sexTpl'},
                {field: 'age', title: '年龄', sort: true,},
                {field: 'address', title: '地区', sort: true,},
                {field: 'income', title: '收益总额', sort: true,},
                {field: 'gold', title: '金币总额', sort: true,},
                {field: 'materials', title: '材料数量', sort: true,},
                {field: 'integral', title: '积分数量', sort: true,},
                {field: 'activeState', title: '活跃状态', sort: true,templet: '#activeTpl'},
                {field: 'type', title: '玩家类型', sort: true, templet: '#typeTpl',},
                {field: 'status', title: '状态', sort: true, templet: '#statusTpl'},
                {field: 'status', title: '赠送状态', sort: true, templet: '#givingTpl'},
                {title: '操作', toolbar: '#currentTableBar'}
            ]],
            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            $('#buttonHidden').val('');
            submitInfo();
            return false;
        });
        form.on('select(selectInfo)', function (data) {
            $('#buttonHidden').val('');
            submitInfo();
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '创建玩家',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Member/add',
                    end: function () {
                        /*删除session无用图片*/
                        $.ajax({
                            url: '/admin/Member/clearSession',
                            type: 'post',
                            dataType: 'json',
                        });
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if(obj.event==='countNum'){
                $('#buttonHidden').val('countNum');
                submitInfo();
                return false;
            }else if(obj.event==='activated'){
                $('#buttonHidden').val('activated');
                submitInfo();
                return false;
            }else if(obj.event==='fictitious'){
                $('#buttonHidden').val('fictitious');
                submitInfo();
                return false;
            }else if(obj.event==='notActive'){
                $('#buttonHidden').val('notActive');
                submitInfo();
                return false;
            }else if(obj.event==='notGiving'){
                $('#buttonHidden').val('notGiving');
                submitInfo();
                return false;
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '用户详情',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Member/write?code=' + data.code,
                    end: function () {
                        /*删除session无用图片*/
                        $.ajax({
                            url: '/admin/Member/clearSession',
                            type: 'post',
                            dataType: 'json',
                        });
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });
        function submitInfo() {
            var d = {};
            var t = $('#formInfo [name]').serializeArray();
            $.each(t, function () {
                d[this.name] = this.value;
            });
            var result = JSON.stringify(d);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        };
    });
</script>

</body>
</html>